/**
 * 统一ajax处理事件控制模块定义
 */
layui.define(['jquery'],function(exports){
    $ = layui.jquery;
    var methods = {
        begin: function(){
            $(document).ajaxComplete(function(event, xhr, options) {
                if(xhr.responseJSON!=null){
                    var rw=xhr.responseJSON;
                    if (rw.resultType == 'WARN') {
                        layer.msg(rw.msg,{icon: 0});
                    } else if (rw.resultType == 'ERROR') {
                        layer.msg(rw.msg, {icon: 5});
                    } else if (rw.resultType == 'NOT_LOGIN') {
                        layer.msg("您还未登录");
                        top.location.href = "/page/login/login.html";
                    }
                }
            });

            //搜索enter事件
            $(".searchVal").on('keydown', function(event) {
                if(event.keyCode ==13){
                    $(".search_btn").click();
                    return false;
                }
            });
        },
        //刷新缓存用户
        refreshCurrentUser:function(){
            //开启同步
            $.ajaxSettings.async = false;
            $.get(layui.sessionData("bgConfig").backUrl + '/user/getCurrentUserDetail', function (rw) {
                if (rw.resultType == 'SUCCESS') {
                    layui.sessionData("bgConfig", {
                        key: "user", value: rw.result.user
                    });
                }
            });
            //关闭同步
            $.ajaxSettings.async = true;
        }
    };
    //输出test接口
    exports('commonDeal', methods);
});